package com.ruoyi.lm.controller;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmLevelpackage;
import com.ruoyi.lm.service.ILmLevelpackageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员套餐包Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/levelpackage")
public class LmLevelpackageController extends BaseController
{
    private String prefix = "lm/levelpackage";

    @Autowired
    private ILmLevelpackageService lmLevelpackageService;

    private ShiroUtils shiroUtils;

    @RequiresPermissions("lm:levelpackage:view")
    @GetMapping()
    public String levelpackage()
    {
        return prefix + "/levelpackage";
    }

    /**
     * 查询会员套餐包列表
     */
    @RequiresPermissions("lm:levelpackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmLevelpackage lmLevelpackage)
    {
        startPage();
        List<LmLevelpackage> list = lmLevelpackageService.selectLmLevelpackageList(lmLevelpackage);
        return getDataTable(list);
    }

    /**
     * 导出会员套餐包列表
     */
    @RequiresPermissions("lm:levelpackage:export")
    @Log(title = "会员套餐包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmLevelpackage lmLevelpackage)
    {
        List<LmLevelpackage> list = lmLevelpackageService.selectLmLevelpackageList(lmLevelpackage);
        ExcelUtil<LmLevelpackage> util = new ExcelUtil<LmLevelpackage>(LmLevelpackage.class);
        return util.exportExcel(list, "levelpackage");
    }

    /**
     * 新增会员套餐包
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员套餐包
     */
    @RequiresPermissions("lm:levelpackage:add")
    @Log(title = "会员套餐包", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmLevelpackage lmLevelpackage)
    {
        lmLevelpackage.setCreateUser(ShiroUtils.getSysUser().getLoginName());
        return toAjax(lmLevelpackageService.insertLmLevelpackage(lmLevelpackage));
    }

    /**
     * 修改会员套餐包
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmLevelpackage lmLevelpackage = lmLevelpackageService.selectLmLevelpackageById(id);
        mmap.put("lmLevelpackage", lmLevelpackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员套餐包
     */
    @RequiresPermissions("lm:levelpackage:edit")
    @Log(title = "会员套餐包", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmLevelpackage lmLevelpackage)
    {
        return toAjax(lmLevelpackageService.updateLmLevelpackage(lmLevelpackage));
    }

    /**
     * 删除会员套餐包
     */
    @RequiresPermissions("lm:levelpackage:remove")
    @Log(title = "会员套餐包", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        if("821555023015055360".equals(ids)){
             return error("注册赠送套餐不能删除!");
        }
        return toAjax(lmLevelpackageService.deleteLmLevelpackageByIds(ids));
    }
}
